package com.ruoyi.business.controller;

import com.ruoyi.business.service.IWsdDishesService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.WsdDishes;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 菜品信息Controller
 * 
 * @author ruoyi
 * @date 2024-04-22
 */
@RestController
@RequestMapping("/wsd_dishes")
public class WsdDishesController extends BaseController
{
    @Autowired
    private IWsdDishesService wsdDishesService;

    /**
     * 查询菜品信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:dishes:list')")
    @GetMapping("/list")
    public TableDataInfo list(WsdDishes wsdDishes)
    {
        startPage();
        List<WsdDishes> list = wsdDishesService.selectWsdDishesList(wsdDishes);
        return getDataTable(list);
    }

    /**
     * 导出菜品信息列表
     */
    @PreAuthorize("@ss.hasPermi('business:dishes:export')")
    @Log(title = "菜品信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WsdDishes wsdDishes)
    {
        List<WsdDishes> list = wsdDishesService.selectWsdDishesList(wsdDishes);
        ExcelUtil<WsdDishes> util = new ExcelUtil<WsdDishes>(WsdDishes.class);
        util.exportExcel(response, list, "菜品信息数据");
    }

    /**
     * 获取菜品信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('business:dishes:query')")
    @GetMapping(value = "/{dishId}")
    public AjaxResult getInfo(@PathVariable("dishId") Long dishId)
    {
        return success(wsdDishesService.selectWsdDishesByDishId(dishId));
    }

    /**
     * 新增菜品信息
     */
    @PreAuthorize("@ss.hasPermi('business:dishes:add')")
    @Log(title = "菜品信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WsdDishes wsdDishes)
    {
        return toAjax(wsdDishesService.insertWsdDishes(wsdDishes));
    }

    /**
     * 修改菜品信息
     */
    @PreAuthorize("@ss.hasPermi('business:dishes:edit')")
    @Log(title = "菜品信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WsdDishes wsdDishes)
    {
        return toAjax(wsdDishesService.updateWsdDishes(wsdDishes));
    }

    /**
     * 删除菜品信息
     */
    @PreAuthorize("@ss.hasPermi('business:dishes:remove')")
    @Log(title = "菜品信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{dishIds}")
    public AjaxResult remove(@PathVariable Long[] dishIds) {
        return toAjax(wsdDishesService.deleteWsdDishesByDishIds(dishIds));
    }
}
